﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ServiceModel.DomainServices.Client.ApplicationServices;
using System.Security.Principal;
using System.Threading;

namespace WebProject.Controls
{
    public class WebContext
    {

        public MockAuthentication Authentication { get; set; }
    }


    public class TestUser : IPrincipal
    {

        #region IPrincipal Member

        public IIdentity Identity
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsInRole(string role)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class MockAuthentication : AuthenticationService
    {
        public static IPrincipal MockUser { get; set; }

        private readonly IPrincipal _defaultUser;

        public MockAuthentication(IPrincipal defaultUser)
        {
            this._defaultUser = defaultUser;
        }

        protected override IPrincipal CreateDefaultUser()
        {
            return this._defaultUser;
        }

        protected override IAsyncResult BeginLoadUser(AsyncCallback callback, object state)
        {
            IAsyncResult result = new MockAsyncResult(state);
            Deployment.Current.Dispatcher.BeginInvoke(
   () => callback(new MockAsyncResult(state)));
            return result;
        }

        protected override LoadUserResult EndLoadUser(IAsyncResult asyncResult)
        {
            return new LoadUserResult(MockAuthentication.MockUser);
        }

        // ...

        private class MockAsyncResult : IAsyncResult
        {
            private readonly object _asyncState;

            public MockAsyncResult(object asyncState)
            {
                this._asyncState = asyncState;
            }

            public object AsyncState { get { return this._asyncState; } }
            public WaitHandle AsyncWaitHandle { get { throw new NotImplementedException(); } }
            public bool CompletedSynchronously { get { return false; } }
            public bool IsCompleted { get { return true; } }
        }

        protected override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
        {
            throw new NotImplementedException();
        }

        protected override IAsyncResult BeginLogout(AsyncCallback callback, object state)
        {
            throw new NotImplementedException();
        }

        protected override IAsyncResult BeginSaveUser(IPrincipal user, AsyncCallback callback, object state)
        {
            throw new NotImplementedException();
        }

        protected override LoginResult EndLogin(IAsyncResult asyncResult)
        {
            throw new NotImplementedException();
        }

        protected override LogoutResult EndLogout(IAsyncResult asyncResult)
        {
            throw new NotImplementedException();
        }

        protected override SaveUserResult EndSaveUser(IAsyncResult asyncResult)
        {
            throw new NotImplementedException();
        }
    }
}
